#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int switchPin1 = 8;
int buttonState1 = 0;
int stage1 = 0;
int leftCount = 0;
const int switchPin2 = 9;
int buttonState2 = 0;
int stage2 = 0;
int rightCount = 0;
const int switchPin3 = 10;
int buttonState3 = 0;
int stage3 = 0;
int XCount = 0;
const int switchPin4 = 11;
int buttonState4 = 0;
int stage4 = 0;
int lineCount = 0;
const int switchPin5 = 12;
int buttonState5 = 0;
int stage5 = 0;
int entCount = 0;
const int switchPin6 = 13;
int buttonState6 = 0;
int stage6 = 0;
int modeCount = 0;
int X = 0;
int line = 1;
int positionX1=1,positionX2=1,positionX3=1;
int X11=1,X12=1,X21=1,X22=1,X23=1,X31=1,X32=1,X33=1,X34=1;
int count1=0,count2=0,count3=0;
int positionY1=1;
int Y1=1,Y2=1,Y3=1,Y4=1,Y5=1,Y6=1,Y7=1,Y8=1,Y9=1,Y10=1,Y11=1,Y12=1,Y13=1;
int modeCount1=0,modeCount2=0,modeCount3=0;
int Time1 = 0;

void leftButtonStage(int leftStage) {
  switch (leftStage){
    case 0 : {
     if(buttonState1 == 1) {
         stage1++;
     }
     break;
    }
    case 1 : {
      if(buttonState1 == 0){
        stage1++;
      }
      break;
    }
    case 2 : {
      leftCount = 1;
      stage1 = 0;
      break;
    }
  }    
}

void rightButtonStage(int rightStage) {
  switch (rightStage){
    case 0 : {
     if(buttonState2 == 1) {
         stage2++;
     }
     break;
    }
    case 1 : {
      if(buttonState2 == 0){
        stage2++;
      }
      break;
    }
    case 2 : {
      rightCount = 1;
      stage2 = 0;
      break;
    }
  }    
}

void XButtonStage(int XStage) {
  switch (XStage){
    case 0 : {
     if(buttonState3 == 1) {
         stage3++;
     }
     break;
    }
    case 1 : {
      if(buttonState3 == 0){
        stage3++;
      }
      break;
    }
    case 2 : {
      XCount = 1;
      stage3 = 0;
      break;
    }
  }    
}

void lineButtonStage(int lineStage) {
  switch (lineStage){
    case 0 : {
     if(buttonState4 == 1) {
         stage4++;
     }
     break;
    }
    case 1 : {
      if(buttonState4 == 0){
        stage4++;
      }
      break;
    }
    case 2 : {
      lineCount = 1;
      stage4 = 0;
      break;
    }
  }    
}

void entButtonStage(int entStage) {
  switch (entStage){
    case 0 : {
     if(buttonState5 == 1) {
         stage5++;
     }
     break;
    }
    case 1 : {
      if(buttonState5 == 0){
        stage5++;
      }
      break;
    }
    case 2 : {
      entCount++;
      stage5 = 0;
      break;
    }
  }    
}

void modeButtonStage(int modeStage) {
  switch (modeStage){
    case 0 : {
     if(buttonState6 == 1) {
         stage6++;
     }
     break;
    }
    case 1 : {
      if(buttonState6 == 0){
        stage6++;
      }
      break;
    }
    case 2 : {
      modeCount++;
      stage6 = 0;
      break;
    }
  }    
}

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  pinMode(switchPin1, INPUT);
  // Print a message to the LCD.
  lcd.clear();
  lcd.print("welcome!!!");
}

void loop() {
  int wTime = millis()/1000;
  if(wTime == 2) lcd.clear();
  if(wTime > 2){
    buttonState1 = digitalRead(switchPin1);
    buttonState2 = digitalRead(switchPin2);
    buttonState3 = digitalRead(switchPin3);
    buttonState4 = digitalRead(switchPin4);
    buttonState5 = digitalRead(switchPin5);
    buttonState6 = digitalRead(switchPin6);
    leftButtonStage(stage1);
    rightButtonStage(stage2);
    XButtonStage(stage3);
    lineButtonStage(stage4);
    entButtonStage(stage5);
    modeButtonStage(stage6);
